<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/vue/dist/vue.js"></script>
</head>
<body>
    

    <div id="app">


        <!-- v-show指令是通过元素样式display控制元素的显示或隐藏 -->
        <h1 v-if="flag">{{msg}}</h1>

        <!-- 原生事件onclick -->
        <button @click="showOrHide">{{txt}}</button>

    </div>

    <script>

        new Vue({
            el: '#app',
            data: {
                msg: 'hello vue.js',
                flag: true,
                txt: '隐藏'
            },
            methods: {
                showOrHide() {
                    // if (this.flag) {
                    //     this.txt = '显示';
                    // } else {
                    //     this.txt = '隐藏';
                    // }
                    this.txt = (this.flag) ? '显示' : '隐藏';
                    this.flag = !this.flag;
                }
            }  
        })


    </script>

</body>
</html>